package com.songlanyun.modules.skus.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.songlanyun.common.drive.RootEntity;
import com.songlanyun.common.utils.SpringContextUtils;
import com.songlanyun.common.validator.group.AddGroup;
import com.songlanyun.common.validator.group.UpdateGroup;
import com.songlanyun.modules.category.entity.SystemProductCategoryEntity;
import com.songlanyun.modules.group.entity.ProductGoodsGroupEntity;
import com.songlanyun.modules.group.service.ProductGoodsGroupService;
import com.songlanyun.modules.skus.service.ProductSkusService;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.*;

/**
 * 商家的商品规格表，创建了之后，对于已有的规格，在发布商品时只需要选择
 * 
 * @author lubo
 * @email sunlightcs@gmail.com
 * @date 2020-11-03 15:46:49
 */
@Data
@TableName("yxt_product_skus")
//@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
public class ProductSkusEntity  extends RootEntity<Long, ProductSkusEntity>  implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 * 
	 */
	@TableId
	@NotNull(message="修改时必须指定商品规格Id",groups = {UpdateGroup.class})
	@Null(message = "新增时不能指定商品规格Id",groups = {AddGroup.class})
	private Long id;
	/**
	 * 商家让铺Id
	 */
	private Long shopId;
	/**
	 * 上级sku_id
	 */
	private Long parentSkuId;
	/**
	 * sku的名称
	 */
	@NotBlank(message="商品规格名称不能为空",groups = {AddGroup.class,UpdateGroup.class})
	@Length(min = 1,max = 20,message = "商品规格名称长度在1-20个字",groups = {AddGroup.class,UpdateGroup.class})
	private String name;
	/**
	 * 顺序
	 */
	@Max(value = 999999,message = "顺序值最大999999",groups = {AddGroup.class,UpdateGroup.class})
	@Min(value = 0,message = "最小顺序值是0",groups = {AddGroup.class,UpdateGroup.class})
	private Integer orderIndex;

	@Override
	public Long getIdentity() {
		return getId();
	}

	@TableField(exist = false)
	private List<ProductSkusEntity> children;
	/**
	 * 获得所有子分组
	 * @return
	 */
	@JsonIgnore
	public List<ProductSkusEntity> loadChildren()
	{
		if(children==null)
		{
			children = ((ProductSkusService) SpringContextUtils.getBean("productSkusService")).getChildren(this.getShopId(),this.getId());
		}
		return children;
	}
}
